package week08;
import java.util.ArrayList;
import java.util.Scanner;
interface IntegerStack {
    Integer push(Integer item); 
    Integer pop();              
    Integer peek();             
    boolean empty();            
    int size();                 
}
class ArrayListIntegerStack implements IntegerStack{
    ArrayList<Integer> list;

    public ArrayListIntegerStack() {
        list = new ArrayList<Integer>();
    }

   
    public Integer push(Integer item) {
        if(item == null ) {
            return null;
        }
        list.add(item);
        return item;
    }

    
    public Integer pop() {
        if(list.isEmpty())
        return null;
        return list.remove(list.size()-1);
    }

   
    public Integer peek() {
        if(list.isEmpty())
            return null;
        return list.get(list.size()-1);
    }

    
    public boolean empty() {
        return list.isEmpty();
    }

   
    public String toString() {
        return list.toString();
    }

    
    public int size() {
        return list.size();
    }
}
public class week0801 {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayListIntegerStack list = new ArrayListIntegerStack();
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            System.out.println(list.push(sc.nextInt()));
        }
        System.out.println(list.peek()+ ","+list.empty()+","+list.size());
        System.out.println(list);
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            System.out.println(list.pop());
        }
        System.out.println(list.peek()+ ","+list.empty()+","+list.size());
        System.out.println(list);
        sc.close();
    }

}

	